package com.aisi.manager.controller;

import com.aisi.manager.service.SysUserService;
import com.aisi.model.dto.system.AssginRoleDto;
import com.aisi.model.dto.system.SysUserDto;
import com.aisi.model.entity.system.SysUser;
import com.aisi.model.vo.common.Result;
import com.aisi.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: shenjianZ
 * @Date: 2024/2/17 13:44
 * @Description:
 */

@RestController
@RequestMapping("/admin/system/sysUser")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @GetMapping("/findSysUserByPage/{pageNum}/{pageSize}")
    public Result findSysUserByPage(@PathVariable("pageNum") Integer pageNum,
                                    @PathVariable("pageSize") Integer pageSize,
                                    SysUserDto sysUserDto) {
        PageInfo<SysUser> pageInfo = sysUserService.findSysUserByPage(pageNum, pageSize,sysUserDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser) {
        sysUserService.saveSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PutMapping("/updateSysUser")
    public Result updateSysUser( @RequestBody SysUser sysUser) {
        sysUserService.updateSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/deleteSysUser/{userId}")
    public Result deleteSysUserById(@PathVariable("userId") Long id) {
        sysUserService.deleteSysUserById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginRoleDto assginRoleDto) {
        sysUserService.doAssign(assginRoleDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


}
